package com.example.shiptask.adapter;
import java.util.List;

import com.example.shiptask.R;
import com.example.shiptask.entity.MakeToOrderEntivity;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MakeToOrderAdapter extends BaseAdapter  {

	private Context context;

	private List<?> list;

	private int resource;

	private ViewGroup groupV;


	public MakeToOrderAdapter(Context context, List<?> paramList,int resource) {
		this.context = context;
		this.list = paramList;
		this.resource = resource;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {

		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {

		ViewHolder holder;
		if (convertView == null) {
			convertView = View.inflate(context, resource, null);
			holder = new ViewHolder();
			holder.cargo=(TextView)convertView.findViewById(R.id.carge);
			holder.line=(TextView)convertView.findViewById(R.id.line);
			holder.ord_fee=(TextView)convertView.findViewById(R.id.ord_fee);
			holder.ord_pay=(TextView)convertView.findViewById(R.id.ord_pay);
			holder.ord_weight=(TextView)convertView.findViewById(R.id.ord_weight);
			holder.contactPhone = (TextView) convertView.findViewById(R.id.ele_contact_phone);
			holder.conView=(LinearLayout)convertView.findViewById(R.id.titleLin);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		groupV = (ViewGroup)holder.conView;
		MakeToOrderEntivity content = (MakeToOrderEntivity) list.get(position);
		holder.cargo.setText(content.getCargoName());
		holder.line.setText(content.getStartPort()+"--"+content.getCargoName());
		holder.ord_weight.setText(content.getrAmount());
		holder.ord_pay.setText(content.getAccountMethod());
		holder.ord_fee.setText(content.getFareUnit());
		for(int i = 0;i < groupV.getChildCount();i++) {
			TextView tv = (TextView)groupV.getChildAt(i);
			tv.setTextColor(Color.rgb(255, 104, 0));
		}
		holder.conView.setBackgroundResource(R.color.ele_title_bg_unconfirm);
		holder.conView.setBackgroundResource(R.color.ele_con_bg_unconfirm);
		holder.contactPhone.setBackgroundResource(R.color.red);
		return convertView;
	}

	static class ViewHolder {
		TextView cargo;
		TextView line;
		TextView contactPhone;
		TextView ord_weight;
		TextView ord_pay;
		TextView ord_fee;
		LinearLayout conView;
	}



}
